#ifndef _SINGLETON_H_
#define _SINGLETON_H_


template <typename T>
class Singleton
{
public:
    template <typename ... Args>
    static T* instance(Args ... args)
        {
            if (instance_ == nullptr)
                instance_ = new T(args...);

            return instance_;
        }

    static void destroy()
        {
            delete instance_;
            instance_ = nullptr;
        }

protected:
    Singleton() {}
    ~Singleton() {}

private:
    Singleton(const Singleton&) = delete;
    Singleton& operator=(const Singleton&) = delete;

    static T* instance_;
};

template <typename T>
T* Singleton<T>::instance_ = nullptr;

#endif /* _SINGLETON_H_ */
